import {
  getCategoryOne,
  getCategoryThree,
  getCategoryTwo,
} from "@/api/product/category";
import type { responseCategory } from "@/api/product/type/type";
import { defineStore } from "pinia";
import { ref } from "vue";
//商品分类的仓库,因为平台属性管理页面的父组件需要用到子组件请求到的数据，这里统一仓库全局管理
const productCategoryStore = defineStore("proCategory", () => {
  //存贮一级分类id
  const c1Id = ref<number | string>("");
  //存贮一级分类数据
  const c1Data = ref<responseCategory>([]);
  //获取一级分类数据
  const getC1 = async () => {
    c1Data.value = await getCategoryOne();
  };
  //存储二级分类ID
  const c2Id = ref<number | string>("");
  //存储二级分类数据
  const c2Data = ref<responseCategory>([]);
  //获取二级分类数据
  const getC2 = async () => {
    const res = await getCategoryTwo(c1Id.value as number);
    c2Data.value = res;
  };
  //存储三级分类ID
  const c3Id = ref<number | string>("");
  //存储二级分类数据
  const c3Data = ref<responseCategory>([]);
  //获取二级分类数据
  const getC3 = async () => {
    const res = await getCategoryThree(c2Id.value as number);
    c3Data.value = res;
  };

  return {
    getC1,
    c1Data,
    c1Id,
    c2Id,
    getC2,
    c2Data,
    c3Data,
    getC3,
    c3Id,
  };
});
export default productCategoryStore;
